/* GUI CONVERTED from reoptr10.p (converter v1.76) Sun Aug 25 20:59:43 2002 */
/* reoptr10.p - LABOR OPERATION TRANSACTION BY PART (REPETITIVE)              */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.15.3.4 $                                                               */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 5.0      LAST MODIFIED: 05/15/89   BY: emb                       */
/* REVISION: 5.0      LAST MODIFIED: 07/03/89   BY: emb                       */
/* REVISION: 5.0      LAST MODIFIED: 10/17/90   BY: emb *B801*                */
/* REVISION: 6.0      LAST MODIFIED: 06/18/90   BY: emb                       */
/* REVISION: 6.0      LAST MODIFIED: 07/25/90   BY: emb                       */
/* REVISION: 6.0      LAST MODIFIED: 09/24/90   BY: SMM *D072*                */
/* REVISION: 6.0      LAST MODIFIED: 10/10/90   BY: SMM *D085*                */
/* REVISION: 6.0      LAST MODIFIED: 11/20/90   BY: emb *D223*                */
/* REVISION: 6.0      LAST MODIFIED: 12/19/90   BY: emb *D265*                */
/* REVISION: 6.0      LAST MODIFIED: 01/11/91   BY: emb *D297*                */
/* REVISION: 6.0      LAST MODIFIED: 03/29/91   BY: emb *D448*                */
/* REVISION: 6.0      LAST MODIFIED: 04/08/91   BY: emb *D485*                */
/* REVISION: 6.0      LAST MODIFIED: 04/09/91   BY: WUG *D503*                */
/* REVISION: 6.0      LAST MODIFIED: 05/09/91   BY: emb *D633*                */
/* REVISION: 6.0      LAST MODIFIED: 06/07/91   BY: emb *D680*                */
/* REVISION: 6.0      LAST MODIFIED: 06/14/91   BY: emb *D705*                */
/* REVISION: 6.0      LAST MODIFIED: 07/02/91   BY: emb *D744*                */
/* REVISION: 6.0      LAST MODIFIED: 08/01/91   BY: emb *D805*                */
/* REVISION: 6.0      LAST MODIFIED: 08/02/91   BY: emb *D808*                */
/* REVISION: 6.0      LAST MODIFIED: 08/08/91   BY: pma *D806*                */
/* REVISION: 6.0      LAST MODIFIED: 10/03/91   BY: alb *D887*(rev only)      */
/* REVISION: 6.0      LAST MODIFIED: 12/03/91   BY: emb *D955*(rev only)      */
/* REVISION: 6.0      LAST MODIFIED: 12/06/91   BY: emb *D955*(rev only)      */
/* REVISION: 7.0      LAST MODIFIED: 10/08/91   BY: pma *F003*                */
/* REVISION: 6.0      LAST MODIFIED: 12/17/91   BY: pma *D967*                */
/* REVISION: 7.0      LAST MODIFIED: 02/25/92   BY: emb *F234*                */
/* REVISION: 7.0      LAST MODIFIED: 03/09/92   BY: smm *F230*                */
/* REVISION: 7.0      LAST MODIFIED: 03/23/92   BY: pma *F089*                */
/* REVISION: 7.0      LAST MODIFIED: 03/29/92   BY: emb *F331*                */
/* REVISION: 7.0      LAST MODIFIED: 06/16/92   BY: emb *F620*                */
/* REVISION: 7.0      LAST MODIFIED: 06/17/92   BY: emb *F662*                */
/* REVISION: 7.0      LAST MODIFIED: 06/26/92   BY: emb *F705*                */
/* REVISION: 7.0      LAST MODIFIED: 07/07/92   BY: emb *F729*                */
/* REVISION: 7.3      LAST MODIFIED: 10/12/92   BY: emb *G184*                */
/* Revision: 7.3      Last edit    : 09/27/93   By: jcd *G247*                */
/* REVISION: 7.3      LAST MODIFIED: 11/04/92   BY: emb *G269*                */
/* REVISION: 7.3      LAST MODIFIED: 11/16/92   BY: emb *G320*                */
/* REVISION: 7.3      LAST MODIFIED: 11/30/92   BY: emb *G370*                */
/* REVISION: 7.3      LAST MODIFIED: 12/29/92   BY: pma *G382*                */
/* REVISION: 7.3      LAST MODIFIED: 11/04/92   BY: emb *G689*                */
/* REVISION: 7.3      LAST MODIFIED: 02/26/93   BY: emb *G760*                */
/* REVISION: 7.3      LAST MODIFIED: 03/02/93   BY: emb *G767*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 04/21/93   BY: pma *GA01*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 07/21/93   BY: qzl *GD44*(rev only)      */
/* REVISION: 7.4      LAST MODIFIED: 07/22/93   BY: pcd *H039*                */
/* REVISION: 7.4      LAST MODIFIED: 01/12/94   BY: qzl *H276*                */
/* REVISION: 7.4      LAST MODIFIED: 08/01/94   BY: emb *GL05*                */
/* REVISION: 7.4      LAST MODIFIED: 09/06/94   BY: qzl *FQ82*                */
/* Oracle changes (share-locks)    : 09/12/94   BY: rwl *FR25*                */
/* REVISION: 7.4      LAST MODIFIED: 10/11/94   BY: jxz *FS37*                */
/* REVISION: 7.4      LAST MODIFIED: 10/19/94   BY: pxd *FR91*                */
/* REVISION: 7.4      LAST MODIFIED: 10/21/94   BY: rmh *FR99*                */
/* REVISION: 7.4      LAST MODIFIED: 10/27/94   BY: pxd *FT03*                */
/* REVISION: 7.4      LAST MODIFIED: 11107/94   BY: pxd *FT40*                */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN76*                */
/* REVISION: 7.3      LAST MODIFIED: 12/06/94   BY: emb *FU13*                */
/* REVISION: 7.2      LAST MODIFIED: 11/15/94   BY: AIS *FT71*                */
/* REVISION: 7.5      LAST MODIFIED: 12/09/94   BY: taf *J038*                */
/* REVISION: 7.5      LAST MODIFIED: 12/14/94   BY: mwd *J034*                */
/* REVISION: 7.5      LAST MODIFIED: 01/05/95   BY: pma *J040*                */
/* REVISION: 7.5      LAST MODIFIED: 02/09/95   BY: ktn *J041*                */
/* REVISION: 7.4      LAST MODIFIED: 12/29/94   BY: cpp *FT95*                */
/* REVISION: 7.3      LAST MODIFIED: 02/07/95   BY: qzl *F0H9*                */
/* REVISION: 7.3      LAST MODIFIED: 03/30/95   BY: srk *G0JD*                */
/* REVISION: 7.3      LAST MODIFIED: 05/11/95   BY: ais *G0MM*                */
/* REVISION: 7.4      LAST MODIFIED: 06/16/95   BY: str *G0N9*                */
/* REVISION: 8.5      LAST MODIFIED: 02/14/96   BY: jym *G1N7*                */
/* REVISION: 8.5      LAST MODIFIED: 01/18/96   BY: bholmes *J0FY*            */
/* REVISION: 8.5      LAST MODIFIED: 04/15/96   BY: fwy *J0HT*                */
/* REVISION: 8.5      LAST MODIFIED: 04/16/96   BY: jym *G1Q9*                */
/* REVISION: 8.6      LAST MODIFIED: 06/11/96   BY: aal *K001*                */
/* REVISION: 8.5      LAST MODIFIED: 07/19/96   BY: gwm *J0ZB*                */
/* REVISION: 8.5      LAST MODIFIED: 08/12/96   BY: *J141* Fred Yeadon        */
/* REVISION: 8.6      LAST MODIFIED: 10/23/96   BY: *G2H7* Julie Milligan     */
/* REVISION: 8.6      LAST MODIFIED: 02/18/97   BY: *G2KV* Murli Shastri      */
/* REVISION: 8.6      LAST MODIFIED: 10/24/97   BY: *G2PZ* Manmohan Pardesi   */
/* REVISION: 8.6      LAST MODIFIED: 11/03/97   BY: *G2P5* Manmohan Pardesi   */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates         */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown         */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.15.3.3    BY: Jean Miller       DATE: 05/21/02  ECO: *P05V*  */
/* $Revision: 1.15.3.4 $          BY: Vivek Gogte       DATE: 08/06/02  ECO: *N1QQ*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdtitle.i "2+ "}

{gldydef.i new}
{gldynrm.i new}

define new global shared variable global_rsntyp as character.

define new shared variable gldetail like mfc_logical no-undo initial no.
define new shared variable gltrans like mfc_logical no-undo initial no.
define new shared variable undo-input-top like mfc_logical no-undo.

define new shared variable wr_recno as recid.
define new shared variable wc_recno as recid.
define new shared variable op_recno as recid.
define new shared variable comp like ps_comp.
define new shared variable eff_date as date.
define new shared variable wo_recid as recid.
define new shared variable wo_recno as recid.
define new shared variable ophist_recid as recid.
define new shared variable pay_rate like emp_pay_rate.

define new shared variable start_setup as character label "Start Time"
   format "99:99:XX".
define new shared variable start_run like start_setup.
define new shared variable stop_setup like start_setup
   label "Elapsed or Stop Time".
define new shared variable stop_run like stop_setup.

/*DEFINE VARIABLES FOR CHANGE ATTRIBUTES FEATURE*/
{gpatrdef.i "new shared"}

define new shared variable chg_attr like mfc_logical label "Chg Attributes"
   no-undo.
define new shared variable lotserial like sr_lotser no-undo.
define new shared variable move_to_wkctr like wc_wkctr no-undo.
define new shared variable move_to_mch like wc_mch no-undo.
define new shared variable h_wiplottrace_procs as handle no-undo.
define new shared variable h_wiplottrace_funcs as handle no-undo.
define new shared variable conv_factor as decimal no-undo.
define new shared variable entered_qty_comp as decimal no-undo.
define new shared variable entered_qty_rjct as decimal no-undo.


define new shared variable last_date like op_date.
define new shared variable input_total as decimal format "->>9.9<<"
   label "Input Total".
define new shared variable control_total like input_total
   label "Control Total".

define new shared variable old_emp like op_emp.
define new shared variable downtime like input_total extent 5 label "Down Time".
define new shared variable down_rsn like rsn_code    extent 5 label "Reason".

define new shared variable shift like op_shift.
define new shared variable site like rps_site no-undo.
define new shared variable prline like rps_line no-undo.
define new shared variable part like op_part no-undo.
define new shared variable op like ps_op no-undo.
define new shared variable bom_code as character format "x(18)" label "BOM".
define new shared variable routing  as character format "x(18)" label "Routing".
define new shared variable schedule_id like wo_lot.
define new shared variable ranok as logical no-undo.
define new shared variable emp_recno as recid no-undo.
define new shared variable mod_issrc like mfc_logical label "Modify Backflush".

define variable i as integer.
define variable j as integer.
define variable earn like op_earn.
define variable conv like um_conv label "Conv".
define variable um like pt_um.
define variable down_desc like rsn_desc extent 5.
define variable qty like op_qty_comp.
define variable disp_units as character format "x(15)".
define variable ptstatus like pt_status.
define variable wr_recid as recid.
define variable cancel like mfc_logical no-undo.
define variable locked-file as character.
define variable msg-counter as integer no-undo.
define variable wrlot like wr_lot.
define variable wrop  like wr_op.
define variable undo_tran like mfc_logical no-undo.
define variable msg-type as integer.
define variable msg-arg1 as character format "x(16)" no-undo.
define variable msg-arg2 as character format "x(16)" no-undo.

define buffer ophist for op_hist.

define new shared frame a.
define new shared frame b.

{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/
{wlcon.i}

if is_wiplottrace_enabled() then do:
   run activate_wip_lot_procs.
end.

/* DEFINE VARIABLES FOR BILL OF MATERIAL EXPLOSION*/
{gpxpld01.i "new shared"}

{gpglefdf.i}

assign
   last_date = today
   start_run = "000000"
   stop_run = "000000".

{reopf10a.i} /* Frame a definition */

{reopf10b.i} /* Frame b definition */

/* DISPLAY */
view frame a.
view frame b.

find first ea_mstr no-lock where ea_type = "1" no-error.
if available ea_mstr then earn = ea_earn.

find mfc_ctrl where mfc_field = "rpc_using_new" no-lock no-error.

if available mfc_ctrl and mfc_logical = true then do:
   /* Use of this function not allowed because new Repetitive enabled */
   {pxmsg.i &MSGNUM=5122 &ERRORLEVEL=3}
   message.
   message.
   undo, leave.
end.

mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


   ranok = no.

   {gprun.i ""reoptr1e.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


   if ranok = no then undo mainloop, leave mainloop.

   find emp_mstr where recid(emp_mstr) = emp_recno no-lock.

   old_emp = input op_emp.

   repeat-loop:
   repeat with frame b:
/*GUI*/ if global-beam-me-up then undo, leave.


      run del_sr_wkfl_set_next_previous
         (output cancel).
      if cancel then leave.

      assign prline.

      find first pt_mstr no-lock where pt_part = input part no-error.
      if not available pt_mstr then do:
         {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3}
         if batchrun then do:
            undo mainloop, leave mainloop.
         end.
         else do:
            undo, retry.
         end.
      end.

      global_part = input part.

      find first pt_mstr where pt_part = input part no-lock no-error.

      if available pt_mstr then do:

         display pt_part @ part pt_desc1.

         find ptp_det where ptp_part = pt_part
                        and ptp_site = site
         no-lock no-error.

         if available ptp_det then do:
            if ptp_routing > "" then
               routing = ptp_routing.
            else
               routing = "".
            if ptp_bom_code > "" then
               bom_code = ptp_bom_code.
            else
               bom_code = "".
         end.

         else do:
            routing = if pt_routing > "" then pt_routing else "".
            if pt_bom_code > "" then
               bom_code = pt_bom_code.
            else
               bom_code = "".
         end.

         find first ro_det where
            ro_routing = if routing > "" then routing else pt_part
         no-lock no-error.

         for each lnd_det where
                  lnd_site = site and lnd_part = pt_part
             and (lnd_start <= last_date or lnd_start = ?)
         no-lock with frame b:
            find ln_mstr where ln_line = lnd_line
                           and ln_site = lnd_site
            no-lock no-error.
            leave.
         end.

         display
            routing
            bom_code
         with frame b.

      end.

      find pt_mstr where pt_part = input part no-lock no-error.
      find ptp_det where ptp_part = pt_part
                     and ptp_site = site
      no-lock no-error.

      if available ptp_det then do:
         if ptp_routing > "" then
            routing = ptp_routing.
         else
            routing = ptp_part.
      end.
      else
         routing = if pt_routing > "" then pt_routing else input part.

      find first ro_det where ro_op = input op
                          and ro_routing = routing
      use-index ro_routing no-lock no-error.

      if available ro_det then do:

         display ro_op @ op ro_desc.

         for each lnd_det where
                  lnd_site = site and lnd_part = pt_part
             and (lnd_start <= last_date or lnd_start = ?)
         no-lock with frame b:
            find ln_mstr where ln_line = lnd_line
                           and ln_site = lnd_site
            no-lock no-error.
            leave.
         end.

      end.

      find first lnd_det where lnd_site = site
                           and lnd_part = input part
                          and lnd_line = input prline
      use-index lnd_line no-lock no-error.

      if available lnd_det then do:
         find ln_mstr where ln_line = lnd_line
                        and ln_site = lnd_site
         no-lock no-error.
         display
            lnd_line @ prline.
         if available ln_mstr then
            display ln_desc.
      end.

      find first ln_mstr no-lock where ln_site = site no-error.

      if available ln_mstr or prline <> "" then do:

         find ln_mstr where ln_line = prline
                        and ln_site = site
         no-lock no-error.

         if not available ln_mstr then do:
            /* Site Production line does not exist */
            {pxmsg.i &MSGNUM=8526 &ERRORLEVEL=3}
            next-prompt prline.
            display "" @ ln_desc.
            undo,retry.
         end.

         display ln_desc.

         find first lnd_det where
                    lnd_line = prline
                and lnd_site = site
                and lnd_part = part
                and (lnd_start <= today or lnd_start = ?)
         no-lock no-error.
         if not available lnd_det then do:
            /* Item does not exist on this Production Line */
            {pxmsg.i &MSGNUM=8527 &ERRORLEVEL=3}
            next-prompt prline.
            undo,retry.
         end.

      end.
      else display "" @ ln_desc.

      /* Added section to locate proper schedule to update */
      {gprun.i ""reoptr1b.p""
         "(site, prline, part, op, last_date,
           output routing, output bom_code, output schedule_id)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if keyfunction(lastkey) = "end-error" then undo, retry.

      if schedule_id = ?
      then do:
         msg-type = 3.
         /* Unexploded schedule with consumption period */
         {pxmsg.i &MSGNUM=325 &ERRORLEVEL=msg-type}
         next-prompt part.
         undo, retry.
      end.

      {gprun.i ""reoptr1d.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


      if keyfunction(lastkey) = "end-error" then undo, retry.

      {gprun.i ""regetcum.p""
         "(input part,
           input site,
           input prline,
           input routing,
           input bom_code,
           output wo_recno,
           output undo_tran)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if undo_tran then undo repeat-loop, retry repeat-loop.

      find wo_mstr no-lock where recid(wo_mstr) = wo_recno no-error.

      /*VALIDATE THE OPERATION */
      {reopval.i &part = part
         &routing = routing
         &op = op
         &date = last_date
         &prompt = op
         &frame = "b"
         &leave = ""no""
         &loop = "mainloop"}

      if not available wo_mstr then do:

         ptstatus = pt_status.
         substring(ptstatus,9,1) = "#".
         if can-find(isd_det where isd_status = ptstatus
                               and isd_tr_type = "ADD-RE")
         then do:
            run mfmsg02
               (input 358,
                input 3,
                input pt_status).
            undo repeat-loop, retry repeat-loop.
         end.

         {gprun.i ""rewocr.p"" "(part,last_date)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         find wo_mstr no-lock where recid(wo_mstr) = wo_recno.

         /* CREATE MARKER RECORD */
         {gprun.i ""remkcr.p""
            "(input wo_lot,
              input 1,
              input mfguser,
              input global_userid)" }
/*GUI*/ if global-beam-me-up then undo, leave.


      end.

      find wr_route where wr_lot = wo_lot and wr_op = op
      no-lock no-error.

      if available wr_route then do:
         if not wr_milestone then do:
            find first wr_route where wr_lot = wo_lot
                                  and wr_op > op
            no-lock no-error.
            if available wr_route then do:
               /* Operation not a milestone */
               {pxmsg.i &MSGNUM=560 &ERRORLEVEL=3}
               undo, retry.
            end.
         end.
      end.

      do transaction:

         find wr_route where wr_lot = wo_lot and wr_op = op
         no-lock no-error.

         if not available wr_route then do:
            /* CREATE wr_route from ro_det for part and operation */
            create wr_route.
            assign
               wr_nbr = wo_nbr
               wr_lot = wo_lot
               wr_part = part
               wr_op = op
               wr_start = today
               wr_due = today
               wr_milestone = ro_milestone
               wr_qty_ord = 0
               wr_desc = ro_desc
               wr_wkctr = ro_wkctr
               wr_mch = ro_mch
               wr_setup = ro_setup
               wr_run = ro_run
               wr_move = ro_move
               wr_tool = ro_tool
               wr_mch_op = ro_mch_op
               wr_vend = ro_vend.
         end.

         assign
            wrlot = wr_lot
            wo_recno = recid(wo_mstr)
            wr_recno = recid(wr_route).

      end.

      release wr_route.

      find first wr_route where wr_lot = wrlot
                            and wr_milestone
      no-lock no-error.

      if not available wr_route then
         find last wr_route where wr_lot = wrlot no-lock no-error.

      if available wr_route then wrop = wr_op.

      find wr_route no-lock where recid(wr_route) = wr_recno.

      find ro_det where
           ro_routing = (if wo_routing > "" then wo_routing else wo_part) and
           ro_op = op and
          (ro_start = ? or ro_start <= today) and
          (ro_end = ? or ro_end >= today)
      no-lock no-error.

      if available ro_det then
         display ro_desc.
      else
         display wr_desc @ ro_desc.

      find pt_mstr where pt_part = wr_part no-lock no-error.
      if available pt_mstr then
         display pt_desc1.
      else
         display " " @ pt_desc1.

      status input.

      do transaction
      with frame b:
/*GUI*/ if global-beam-me-up then undo, leave.


         create op_hist.
         {mfnoptr.i}
         assign
            op_part = part
            op_wo_op = op
            op_site = site
            op_line = prline
            op_tran_date = today
            op_date = last_date
            op_recno = recid(op_hist).

         assign
            op_emp
            op_wo_nbr = wr_nbr
            op_shift = shift
            op_wo_lot = wr_lot
            op_type = "LABOR"
            op_wkctr = wr_wkctr
            op_mch = wr_mch
            op_earn = earn
            op_milestone = wr_milestone
            op_qty_comp = wr_qty_wip
            op_std_run = wr_run.

         ophist_recid = recid(op_hist).

         assign
            bombatch = 1
            start_run = stop_run
            stop_run = "000000"
            downtime = 0
            down_rsn = ""
            down_desc = ""
            um = pt_um
            conv = 1.

         display
            op_wkctr
            op_mch
            op_qty_comp
            um
            conv
            " " @ disp_units
            op_qty_rjct
            mod_issrc
            chg_attr
            op_act_run
            op_earn
            start_run
            stop_run
            op_trnbr format ">>>>>>>9"
            op_wo_lot
            downtime[1 for 2]
            down_rsn[1 for 2]
            down_desc[1 for 2].

         find wc_mstr where wc_wkctr = op_wkctr and wc_mch = op_mch
         no-lock no-error.

         if available wc_mstr then do:
            display wc_desc.
            find dpt_mstr no-lock where dpt_dept = wc_dept no-error.
            if available dpt_mstr then do:
               op_dept = wc_dept.
               display
                  op_dept
                  dpt_desc.
            end.
            else
               display
                  " " @ dpt_desc.
         end.
         else
            display
               " " @ wc_desc
               " " @ op_dept
               " " @ dpt_desc.

         if is_wiplottrace_enabled() then do:
            run init_wip_lot_tables.
         end.

         {gprun.i ""reoptr1a.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


         if undo-input-top
            then undo, leave.

         if can-find(first whl_mstr where whl_act = true no-lock)
         then do:

            for each sr_wkfl where sr_userid = mfguser no-lock:
/*GUI*/ if global-beam-me-up then undo, leave.


               /* CREATE A TE_MSTR RECORD */
               {gprun.i ""wireoptr.p""
                  "(input 'wi-reoptr10',
                    input op_hist.op_wkctr,
                    input sr_qty,
                    input sr_site,
                    input sr_loc,
                    input op_hist.op_date,
                    input op_hist.op_shift,
                    input op_hist.op_part,
                    input sr_lotser,
                    input sr_ref,
                    input um,
                    input conv)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            end.
/*GUI*/ if global-beam-me-up then undo, leave.


         end.

         msg-counter = 0.

         repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


            undo-input-top = yes.

            release wo_mstr.
            release wr_route.

            find wo_mstr exclusive-lock where recid(wo_mstr) = wo_recno
            no-wait no-error.

            if available wo_mstr then do:
               find wr_route exclusive-lock where
                  recid(wr_route) = wr_recno no-wait no-error.
            end.

            if locked wo_mstr
            or locked wr_route
            then do:

               if locked wo_mstr then locked-file = "wo_mstr".
               else
               if locked wr_route then locked-file = "wr_route".

               if msg-counter modulo 100 = 0 then do:
                  msg-arg1 = kblabel("end-error").
                  msg-arg2 = fill(".",(msg-counter / 100) mod 20).
                  /* Attempting to lock # record. # to exit */
                  {pxmsg.i &MSGNUM=1400 &ERRORLEVEL=1
                           &MSGARG1=locked-file
                           &MSGARG2=msg-arg1
                           &MSGARG3=msg-arg2}
                  readkey pause 1.
                  if keyfunction(lastkey) = "end-error" then leave.
                  apply lastkey.
               end.

               msg-counter = msg-counter + 1.
               next.

            end.

            if available wo_mstr and available wr_route then do:
               undo-input-top = no.
               leave.
            end.

         end.
/*GUI*/ if global-beam-me-up then undo, leave.


         hide message.

         if undo-input-top then undo, leave.

         pay_rate = wc_lbr_rate.

         if emp_pay_type = "HR" and emp_pay_rate <> 0 then do:
            pay_rate = emp_pay_rate.
            if op_earn <> "" then do:
               find first ea_mstr where ea_earn = op_earn
               no-lock no-error.
               if available ea_mstr then pay_rate = pay_rate * ea_rate.
            end.
         end.

         assign
            wr_act_setup = wr_act_setup + op_act_setup
            wr_act_run = wr_act_run + op_act_run.

         if not wo_lot_rcpt then wo_lot_next = lotserial.

         {gprun.i ""reoptrc.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


         qty = op_qty_comp.

         if wr_op = wrop then
            wr_qty_wip = 0.
         else
            wr_qty_wip = wr_qty_wip - qty.

         assign
            wr_qty_comp = wr_qty_comp + op_qty_comp
            wr_qty_move = wr_qty_move + op_qty_comp
            wr_qty_rjct = wr_qty_rjct + op_qty_rjct
            wr_qty_rwrk = wr_qty_rwrk + op_qty_rwrk.

         if (index("QH",wr_status) > 0 or wr_status = "" )
            and op_act_setup > 0
         then
            wr_status = "S".

         if (index("QHS",wr_status) > 0 or wr_status = "" )
            and op_act_run > 0
         then
            wr_status = "R".

         qty = op_qty_comp + op_qty_rjct.

         /* Post non-milestone operations at standard */
         {gprun.i ""reoptr1c.p""
            "(wr_lot, wr_op, ""LABOR"", wo_recno,
              op_date, op_shift, qty)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         /* UPDATE REPETITIVE SCHEDULE - Routing & Components */
         {gprun.i ""reoptra.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


         if mod_issrc = no then
         for each pk_det exclusive-lock where pk_user = mfguser:
            pk_qty = (pk_qty * (op_qty_comp + op_qty_rjct)) / bombatch.
         end.

         /* CREATE INVENTORY TRANSACTIONS FOR COMPONENTS ISSUED */
         {gprun.i ""rewois.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


         /*BACKFLUSH LIST OF INPUT WIP LOTS AND OUTPUT WIP LOTS. */
         if is_wiplottrace_enabled() and
            is_operation_queue_lot_controlled (wo_lot, op, OUTPUT_QUEUE)
         then do:

            for first op_hist
               where recid(op_hist) = ophist_recid
            no-lock: end.

            run std_labor_backflush_wip_lots in h_wiplottrace_procs
               (input op_trnbr,
                input wr_lot,
                input wr_op,
                input conv_factor,
                input op_site,
                input op_wkctr,
                input op_mch).
         end.
/*GUI*/ if global-beam-me-up then undo, leave.


         qty = op_qty_comp.

         find next wr_route where wr_lot = op_wo_lot
            and wr_op > op_wo_op
         no-lock no-error.

         if available wr_route then do:

            if not wr_milestone then do:

               find first wr_route no-lock where wr_lot = op_wo_lot
                  and wr_op > op_wo_op
                  and wr_milestone = yes no-error.

               if not available wr_route then
               find last wr_route no-lock where wr_lot = op_wo_lot
                  and wr_op > op_wo_op no-error.

            end.

            if is_wiplottrace_enabled() and
               is_operation_queue_lot_controlled (wo_lot, op, OUTPUT_QUEUE)
            then do:
               run std_labor_move_wip_lots in h_wiplottrace_procs
                  (input op_wo_lot,
                   input op_wo_op,
                   input conv_factor,
                   input op_site,
                   input op_wkctr,
                   input op_mch,
                   input move_to_wkctr,
                   input move_to_mch).
            end.

            wr_recid = recid(wr_route).
            find wr_route where recid(wr_route) = wr_recid.
            wr_qty_wip = wr_qty_wip + qty.

         end.

         else do:

            if available wo_mstr then do:

               if batchrun then do:

                  find first pt_mstr where pt_part = wo_part
                  no-lock no-error.

                  find first pl_mstr where pl_prod_line = pt_prod_line
                  no-lock no-error.

                  if not available pl_mstr then do:
                     /* Product Line not found */
                     {pxmsg.i &MSGNUM=59 &ERRORLEVEL=4}
                     undo mainloop, leave mainloop.
                  end.

               end.

               wo_recid = recid(wo_mstr).
               {gprun.i ""reisrc04.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


            end.

         end.

         if is_wiplottrace_enabled() and
            is_operation_queue_lot_controlled (wo_lot, op, OUTPUT_QUEUE)
         then do:

            if entered_qty_rjct <> 0 then do:
               run std_labor_reject_wip_lots in h_wiplottrace_procs
                  (input ophist_recid,
                   input conv_factor,
                   input op_wkctr,
                   input op_mch).
            end.

         end.

         run downtime_trans (input ophist_recid).

      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      run del_marker (input wo_lot).

   end.
/*GUI*/ if global-beam-me-up then undo, leave.


   if control_total <> input_total then do:
      /* Batch control total does not match total */
      {pxmsg.i &MSGNUM=1151 &ERRORLEVEL=2}
   end.

end.

status input.

if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_procs no-error.
if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_funcs no-error.

PROCEDURE mfmsg02:
   define input parameter p_msg_nbr as integer no-undo.
   define input parameter p_msg_severity as integer no-undo.
   define input parameter p_msg_string as character no-undo.

   {pxmsg.i &MSGNUM=p_msg_nbr &ERRORLEVEL=p_msg_severity
            &ERRORLEVEL=p_msg_string}

END PROCEDURE.

PROCEDURE activate_wip_lot_procs:

   {gprunmo.i &program=""wlpl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_procs"""}

   {gprunmo.i &program=""wlfl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_funcs"""}

END PROCEDURE.

PROCEDURE init_wip_lot_tables:

   run init_bkfl_input_wip_lot_temptable in h_wiplottrace_procs.
   run init_bkfl_output_wip_lot_temptable in h_wiplottrace_procs.
   run init_bkfl_reject_wip_lot_temptable in h_wiplottrace_procs.

END PROCEDURE.

PROCEDURE downtime_trans:
   define input parameter ophist_recid as recid no-undo.

   /* DOWNTIME TRANSACTIONS */
   for first ophist where recid(ophist) = ophist_recid
   no-lock: end.

   do i = 1 to 2:
      if downtime[i] <> 0 or down_rsn[i] <> "" then do:
         {gprun.i ""reoptrd.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

         leave.
      end.
   end.

END PROCEDURE.

PROCEDURE del_marker:
   define input parameter id_nbr like wo_lot no-undo.

   /* DELETE MARKER RECORD */
   {gprun.i ""remkcr.p""
      "(input id_nbr,
        input 2,
        input mfguser,
        input global_userid)" }
/*GUI*/ if global-beam-me-up then undo, leave.


END PROCEDURE.

PROCEDURE exec_warehouse:
   define input parameter wkctr like op_wkctr no-undo.
   define input parameter date like op_date no-undo.
   define input parameter shift like op_shift no-undo.
   define input parameter part like op_part no-undo.
   define input parameter um like pt_um no-undo.
   define input parameter conv like um_conv no-undo.

   if can-find(first whl_mstr where whl_act = true no-lock)
   then do:

      for each sr_wkfl where sr_userid = mfguser no-lock:
/*GUI*/ if global-beam-me-up then undo, leave.


         /* CREATE A TE_MSTR RECORD */
         {gprun.i ""wireoptr.p""
            "(input 'wi-reoptr10',
              input wkctr,
              input sr_qty,
              input sr_site,
              input sr_loc,
              input date,
              input shift,
              input part,
              input sr_lotser,
              input sr_ref,
              input um,
              input conv)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      end.
/*GUI*/ if global-beam-me-up then undo, leave.


   end.

END PROCEDURE.

PROCEDURE del_sr_wkfl_set_next_previous:
   define output parameter cancel like mfc_logical initial yes no-undo.

   for each sr_wkfl exclusive-lock where sr_userid = mfguser:
      delete sr_wkfl.
   end.

   {gprun.i ""gplotwdl.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


   assign
      wrop = 0.

   set
      part
      op
      prline
   with frame b
   editing:

      global_part = input part.

      if frame-field = "part" then do:

         /* FIND NEXT/PREVIOUS RECORD */
         {mfnp.i pt_mstr part pt_part part pt_part pt_part}

         if recno <> ? then do:

            display pt_part @ part pt_desc1 with frame b.

            find ptp_det no-lock where ptp_part = pt_part
               and ptp_site = site no-error.

            if available ptp_det then do:
               if ptp_routing > "" then
                  routing = ptp_routing.
               else
                  routing = "".
               if ptp_bom_code > "" then
                  bom_code = ptp_bom_code.
               else
                  bom_code = "".
            end.

            else do:
               routing = if pt_routing > "" then pt_routing else "".
               if pt_bom_code > "" then
                  bom_code = pt_bom_code.
               else
                  bom_code = "".
            end.

            find first ro_det where
               ro_routing = if routing > "" then routing else pt_part
            no-lock no-error.

            if available ro_det then
               display ro_op @ op ro_desc with frame b.
            else
               display "" @ op "" @ ro_desc with frame b.

            display "" @ prline "" @ ln_desc with frame b.

            for each lnd_det where
                     lnd_site = site and lnd_part = pt_part
                and (lnd_start <= last_date or lnd_start = ?)
            no-lock with frame b:

               find ln_mstr where ln_line = lnd_line
                              and ln_site = lnd_site
               no-lock no-error.

               if available ln_mstr then
                  display ln_line @ prline ln_desc with frame b.
               else
                  display "" @ prline "" @ ln_desc with frame b.

               leave.

            end.

            display routing bom_code with frame b.

         end.

         recno = ?.

      end.

      else
      if frame-field = "op"
         and can-find (pt_mstr where pt_part = input part)
      then do:

         find pt_mstr no-lock where pt_part = input part no-error.
         find ptp_det no-lock where ptp_part = pt_part
            and ptp_site = site no-error.

         if available ptp_det then do:
            if ptp_routing > "" then
               routing = ptp_routing.
            else
               routing = ptp_part.
         end.
         else
            routing = if pt_routing > "" then pt_routing
                     else input part.

         /* FIND NEXT/PREVIOUS RECORD */
         {mfnp01.i ro_det op ro_op ro_routing routing
            ro_routing}

         if recno <> ? then do:
            display ro_op @ op ro_desc with frame b.

            display "" @ prline "" @ ln_desc with frame b.

            for each lnd_det no-lock where
                     lnd_site = site and
                     lnd_part = pt_part and
                    (lnd_start <= last_date or lnd_start = ?)
            with frame b:

               find ln_mstr where ln_line = lnd_line
                              and ln_site = lnd_site
               no-lock no-error.

               if available ln_mstr then
                  display ln_line @ prline ln_desc with frame b.
               else
                  display "" @ prline "" @ ln_desc with frame b.

               leave.

            end.

         end.

      end.

      else if frame-field = "prline" then do:

         /* FIND/NEXT PREVIOUS*/
         {mfnp05.i lnd_det lnd_line
            "lnd_site = site and lnd_part = input part"
            lnd_line "input prline"}

         if recno <> ? then do:

            find ln_mstr no-lock where ln_line = lnd_line
                                   and ln_site = lnd_site no-error.

            display lnd_line @ prline with frame b.

            if available ln_mstr then
               display ln_desc with frame b.

         end.

      end.

      else do:
         readkey.
         apply lastkey.
      end.

   end.

   cancel = no.

END PROCEDURE.
